home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
dtk_demo.zip
/
PR_SPOOL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-12
|
6KB
|
210 lines
/* PR_SPOOL.C
* demonstrates interface to print spooler
* last mod.: 09-SEP-91
*/
#include <STDIO.H>
#include <STDLIB.H>
#include <CONIO.H>
#include <L_PRINT.H>
#include <L_STR.H>
#include <L_DIR.H>
Uchar *menu_letters = "SCAHERQ";
Uchar *menu =
"\nS Submit a file C Cancel a file (wildcards OK) A Cancel all files\n"
"H Hold the queue E End the hold R Redisplay queue Q Quit --> ";
Far_str_ptr file_ptrs[_MAX_SPOOL_FILES_];
Uchar filepath[_MAX_PATH_];
void main(int argc, char **argv);
void report_error(int err_num, Str_ptr when);
void display_print_queue(int num_files);
/*----------------------------*/
void main(int argc, char **argv)
{
int i, result, num_files, qnhold=FALSE, which;
Uchar ch=0;
result = print_spool_status();
switch ( result )
{
case 0:
printf("Print spooler is installed.\n");
break;
case -21:
printf("Print spooler is not installed.\n");
break;
case -22:
printf("Print spooler cannot be installed.\n");
exit(-22);
case -23:
printf("DOS version earlier than 3.0.\n");
exit(-23);
default:
printf("print_spool_status() returns error %d.\n",result);
exit(result);
}
if ( result == -21 )
{
printf("Install print spooler? (Y/N) ");
while ( ch != 'Y' && ch != 'N' )
{
ch = (Uchar)getch();
ch -= 32*(ch>'Z');
}
printf("%c\n",ch);
if ( ch == 'N' )
exit(0);
result = print_spool_install(&which);
if ( result != 0 )
{
report_error(result,"installing print spooler");
exit(0);
}
else
printf("PRINT.%s installed.\n",(which==1?"EXE":"COM"));
}
if ( argc > 1 )
{
for ( i=1; i<argc; i++ )
print_spool_submit_file(argv[i]);
/* ignore errors */
}
while ( TRUE )
{
/* check files in the print queue */
num_files = print_spool_hold(NULL);
if ( num_files < 0 )
{
report_error(num_files,"holding the queue");
exit(num_files);
}
else
{
printf("\n%d file%s in print queue:\n",
num_files, ( num_files==1 ? "" : "s" ) );
if ( num_files > 0 )
{
num_files = print_spool_hold(file_ptrs);
if ( num_files < 0 )
{
report_error(num_files,"holding the queue");
exit(num_files);
}
else
{
display_print_queue(num_files);
if ( qnhold )
printf("Print queue on hold.\n");
}
}
}
if ( !qnhold )
print_spool_end_hold();
printf(menu);
ch = -1;
while ( ( i = char_at(menu_letters,ch,0) ) == -1 )
{
ch = (Uchar)getch();
ch -= 32*(ch>'Z');
}
printf("%c\n",ch);
if ( ch == 'Q' )
break; /* quit */
switch ( i )
{
case 0: /* submit a file */
/* allow maximum input of _MAX_PATH_ - 4 characters */
printf("File: ");
gets_n(filepath,_MAX_PATH_-4);
putchar('\n');
trim(filepath);
if ( *filepath )
{
result = print_spool_submit_file(filepath);
if ( result < 0 )
report_error(result,"submitting file");
qnhold = FALSE;
}
break;
case 1: /* cancel a file */
printf("File: ");
gets_n(filepath,_MAX_PATH_-4);
putchar('\n');
trim(filepath);
if ( *filepath )
{
result = print_spool_cancel_file(filepath);
if ( result < 0 )
report_error(result,"cancelling file");
qnhold = FALSE;
}
break;
case 2: /* cancel all files */
print_spool_cancel_all();
if ( result < 0 )
report_error(result,"cancelling all files");
qnhold = FALSE;
break;
case 3: /* hold the queue */
qnhold = TRUE;
break;
case 4: /* end the hold */
qnhold = FALSE;
}
}
}
/*--------------------------*/
void report_error(int err_num,
Str_ptr when)
{
switch ( err_num )
{
case -1: printf("Function invalid"); break;
case -2: printf("File not found"); break;
case -3: printf("Path not found"); break;
case -4: printf("Too many open files"); break;
case -5: printf("Access denied"); break;
case -8: printf("Print queue full"); break;
case -9: printf("Spooler busy"); break;
case -12: printf("Name too long"); break;
case -15: printf("Drive invalid"); break;
case -20: printf("Wildcards"); break;
case -32: printf("Spooler not found"); break;
case -37: printf("Environment too big"); break;
case -38: printf("Spooler not executable"); break;
case -42: printf("Insufficient memory"); break;
default: printf("%d",err_num);
}
printf(" error when %s.\n",when);
}
/*-----------------------------------*/
void display_print_queue(int num_files)
{
int i;
Far_str_ptr ptr;
for ( i=0; i<num_files; i++ )
{
/* file_ptrs[i] is a Far_str_ptr
* so can't use printf("%s",file_ptrs[i])
*/
ptr = file_ptrs[i];
while ( *ptr )
putchar(*ptr++);
putchar('\n');
}
}